﻿using System;
using System.Collections.Generic;
using AppfabricAdministrator.Entities.Interface;

namespace AppfabricAdministrator.Commands.Cluster
{
    public class UseCluster : ICommand
    {
        public string CommandName
        {
            get
            {
                return "Use-CacheCluster";
            }
        }

        private Dictionary<String, Object> _parameters = new Dictionary<String, Object>(){
            {"Provider",null},
            {"ConnectionString",null}
        };

        public Dictionary<String, Object> Parameters
        {
            get
            {
                return _parameters;
            }
            set
            {
                _parameters = value;
            }
        }

        public bool Execute()
        {
            Microsoft.Win32.RegistryKey regRoot = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Appfabric\\V1.0\\Configuration",false);
            if (regRoot != null)
            {
                this.Parameters["Provider"] = regRoot.GetValue("Provider").ToString();
                this.Parameters["ConnectionString"] = regRoot.GetValue("ConnectionString").ToString().Replace("\\ClusterConfig.xml", "");
                return true;
            }
            return false;
        }

        private string _successMessage = "Connected to cache cluster.";
        public string SuccessMessage
        {
            get { return _successMessage; }
        }
    }
}
